<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<script type="text/javascript">
	var area_treegrid;
	$(function() {
		area_treegrid = $('#area_treegrid')
				.treegrid(
						{
							url : '${ctx}/autoinn/area/treegrid',
							idField : 'id',
							treeField : 'text',
							parentField : 'pid',
							rownumbers : true,
							pagination : false,

							sortName : 'sort',
							sortOrder : 'asc',
							frozenColumns : [ [ {
								width : '200',
								title : '名称',
								field : 'text'
							} ] ],
							columns : [ [
									{
										width : '70',
										title : '创建人',
										field : 'createBy'
									},

									{
										width : '120',
										title : '创建时间',
										field : 'createDate'
									},
									{
										title : '操作',
										field : 'action',
										width : '150',
										formatter : function(value, row) {
											var str = "";
											<shiro:hasPermission name="/autoinn/area/cru">
											str += sy
													.formatString(
															'<span onclick="area_editFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
															row.id, "修改");
											</shiro:hasPermission >
											<shiro:hasPermission name="/autoinn/area/delete">
											str += sy
													.formatString(
															'<span onclick="area_removeFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
															row.id, "删除");
											</shiro:hasPermission >

											return str;
										}
									} ] ],
							toolbar : '#area_toolbar',
							onBeforeLoad : function(row, param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(row, data) {
								parent.$.messager.progress('close');
							}
						});
	});
	//添加
	var area_addFun = function() {
		$('<div/>').dialog({
			href : '${ctx}/autoinn/area/cru',
			width : 640,
			height : 180,
			modal : true,
			title : '添加区域',
			buttons : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#area_updateForm').form('submit', {
						url : '${ctx}/autoinn/area/upte/pre',
						success : function(result) {

							try {
								var r = $.parseJSON(result);
								if (r.success) {

									area_treegrid.treegrid('reload'); // 刷新数据  
									d.dialog('destroy');
								}
								$.messager.show({
									title : '温馨提示',
									msg : r.message
								});

							} catch (e) {
								$.messager.alert('温馨提示', r.message);
								return;
							}

						}

					});
				}

			} ],
			onLoad : function() {
				//$("#res_updateForm").form('load',entity);

			},
			onClose : function() {
				$(this).dialog('destroy');
			}
		});

	};

	//查看
	/*var res_lookFun = function(id) {

	};*/

	//修改
	var area_editFun = function(id) {
		$('<div/>').dialog({
			href : '${ctx}/autoinn/area/cru?id=' + id,
			width : 640,
			height : 160,
			modal : true,
			title : '修改区域',
			buttons : [ {
				text : '修改',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#area_updateForm').form('submit', {
						url : '${ctx}/autoinn/area/upte/pre',
						success : function(result) {
							try {
								var r = $.parseJSON(result);
								if (r.success) {
									area_treegrid.treegrid('reload'); // 刷新数据  
									d.dialog('destroy');
								}
								$.messager.show({
									title : '温馨提示',
									msg : r.message
								});

							} catch (e) {
								$.messager.alert('温馨提示', r.message);
								return;
							}

						}

					});
				}

			} ],
			onClose : function() {
				$(this).dialog('destroy');
			},
			onLoad : function() {
				$.post('${ctx}/sys/res/selectById', {
					id : id
				}, function(result) {
					if (result != null) {
						$('#res_updateForm').form('load', result);
					}
					$.messager.progress('close');
				}, 'json');
			}
		});
	};

	//移除
	var area_removeFun = function(id) {
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				$.post('${ctx}/autoinn/area/delete/' + id, {
					id : id
				}, function(data) {
					area_treegrid.treegrid('reload');
					$.messager.alert('温馨提示', data.message);
				}, 'json');
			}
		});
	};

	//展开
	var area_redoFun = function() {
		var node = area_treegrid.treegrid('getSelected');
		if (node) {
			area_treegrid.treegrid('expandAll', node.id);
		} else {
			area_treegrid.treegrid('expandAll');
		}
	};
	//折叠
	var area_undoFun = function() {
		var node = area_treegrid.treegrid('getSelected');
		if (node) {
			area_treegrid.treegrid('collapseAll', node.id);
		} else {
			area_treegrid.treegrid('collapseAll');
		}
	};
</script>

<!-- 界面布局  -->
<div class="easyui-layout" style="width: 100%; height: 100%;"
	data-options="fit:true,border:false">
	<div id="area_toolbar" style="display: none;">
		<table>
			<tr>
				<td>
				<shiro:hasPermission name="/autoinn/area/cru">
				<a href="javascript:void(0);" class="easyui-linkbutton"
					data-options="iconCls:'icon-add',plain:true"
					onclick="area_addFun();">添加</a>
					</shiro:hasPermission></td>
				<td><div class="datagrid-btn-separator"></div></td>
				<td><a onclick="area_redoFun();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-redo'">展开</a> <a
					onclick="area_undoFun();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-undo'">折叠</a></td>
				<td><div class="datagrid-btn-separator"></div></td>
				<td><a onclick="area_treegrid.treegrid('reload');"
					href="javascript:void(0);" class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-reload'">刷新</a></td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',title:'区域列表'" style="padding: 2px;">
		<div class="easyui-layout" data-options="fit : true,border : false">
			<div data-options="region:'center',border:false">
				<table id="area_treegrid"></table>
			</div>
		</div>
	</div>
</div>
